package com.itheima.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;
import java.util.List;

@Configuration
public class RestTemplateConfig {


    @Bean
    public RestTemplate restTemplate(){
        RestTemplate restTemplate = new RestTemplate();
        List<HttpMessageConverter<?>>converters = restTemplate.getMessageConverters();
        HttpMessageConverter<?> converter1 = null;
        for (HttpMessageConverter<?> converter : converters) {
            if (converter.getClass() == StringHttpMessageConverter.class){
                converter1 = converter;
                break;
            }
        }
        if (converter1 !=null){
            converters.remove(converter1);
        }
        HttpMessageConverter<?> con = new StringHttpMessageConverter(StandardCharsets.UTF_8);

        return restTemplate;
    }




}
